<?xml version="1.0"?>
<!DOCTYPE xsl:stylesheet [
  <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#">
  <!ENTITY dc "http://purl.org/dc/elements/1.1/">
  <!ENTITY dcterms "http://purl.org/dc/terms/">
  <!ENTITY foaf "http://xmlns.com/foaf/0.1/">
  <!ENTITY a "http://xmlns.heustics.org/schema/myelin/0.1/">
  <!ENTITY m "http://xmlns.heustics.org/ontology/myelin/0.1/">
]>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
  xmlns:fhttp="http://xmlns.4suite.org/4ss/http"
  xmlns:l="http://xmlns.heustics.org/schema/i18n/0.1/"
  xmlns:a="http://xmlns.heustics.org/schema/myelin/0.1/" 
  xmlns:b="http://xmlns.heustics.org/schema/myelin/0.1/NodeAcl"
  xmlns:o="http://xmlns.heustics.org/schema/myelin/0.1/NodeAcl#edit"
  extension-element-prefixes="fhttp"
  exclude-result-prefixes="xsl a b o l"
>    
  <xsl:variable name="o:l10n" select="a:get-l10n('&a;NodeAcl#edit')"/>
  <xsl:variable name="o:titles-l10n" select="$o:l10n/l:context[@name='titles']/*"/>
  <xsl:variable name="o:params-l10n" select="$o:l10n/l:context[@name='params']/*"/>    
  <xsl:variable name="o:hints-l10n" select="$o:l10n/l:context[@name='param-hints']/*"/>  
    
  <xsl:template match="a:title[@key='edit-acl-group']" mode="a:head-content">
    <xsl:call-template name="a:head-title">
      <xsl:with-param name="title" select="$o:titles-l10n[1]"/>
    </xsl:call-template>
  </xsl:template>
  
  <xsl:template match="a:title[@key='edit-acl-group']" mode="a:page-header">
    <xsl:call-template name="a:page-header-title">
      <xsl:with-param name="title" select="$o:titles-l10n[1]"/>
    </xsl:call-template>
  </xsl:template>   
  
  <xsl:template match="a:form[@msg]" mode="a:form-header" name="a:form-header">
    <xsl:param name="l10n" select="$o:l10n/l:context[@name='form-msg']"/>
    <xsl:param name="msg-key" select="@msg"/>
    <xsl:param name="msg" select="$l10n/*[@key=$msg-key]"/>
    <xsl:if test="$msg">
      <div class="entry msg">      
        <span><xsl:value-of select="$msg"/></span>
        <div class="spacer"/>
      </div>
    </xsl:if>    
    <xsl:apply-imports/>
  </xsl:template>  
      
  <!-- not needed right now 
 
  <xsl:template match="a:acls" mode="a:input-hidden"> 
    <xsl:apply-templates select="a:input-hidden"/>     
  </xsl:template>  
  
  <xsl:template match="a:acl-group" mode="a:input-hidden">
    <input type="hidden" name="acl-group-tag" value="{@tag}"/>   
    <xsl:apply-templates select="a:input-hidden"/>     
  </xsl:template>  
  
  <xsl:template match="a:actions" mode="a:input-hidden">
    <xsl:for-each select="a:selection/*">
      <input type="hidden" name="type" value="{concat(@key,' ',@app-key)}"/>
    </xsl:for-each>            
  </xsl:template>  
  
  <xsl:template match="a:permissions" mode="a:input-hidden">
    <xsl:for-each select="*">
      <xsl:variable name="ln" select="local-name()"/>
      <xsl:for-each select="*">
        <input type="hidden" name="{$ln}-agents" value="{@nick}"/>
      </xsl:for-each>      
    </xsl:for-each>            
  </xsl:template>    
  -->  
    
  <xsl:template match="a:acls" mode="a:input-show">    
    <xsl:apply-templates mode="a:input-show"/>
  </xsl:template>  
  
  <xsl:template match="a:acl-group[@tag]" mode="a:input-show">
    <div class='input text tag'>  
      <div class="key">
        <div>
          <xsl:call-template name="a:label-class-attr"/>
          <span><xsl:value-of select="$o:params-l10n[@key='tag']"/></span>
          <div class="spacer"/>
        </div>        
        <div class='hint'>
          <xsl:call-template name="a:input-hints">
            <xsl:with-param name="hint" select="$o:hints-l10n[@key='tag']"/>
          </xsl:call-template>
          <div class="spacer"/>
        </div>
        <div class="spacer"/>
      </div>      
      <div class='value'>
        <input type="hidden" name="acl-group-tag" value="{@tag}"/>
        <span>
          <xsl:value-of select="@tag"/>
        </span>
        <div class="spacer"/>
      </div>
      <div class='spacer'/>
    </div>
    <xsl:apply-templates mode="a:input-show"/>
  </xsl:template>
  
  <xsl:template match="a:acl-group[@error]" mode="a:input-show">
    <fhttp:response-uri
      uri="{a:format-node-action('view-acls')}"/>
  </xsl:template>
  
  <xsl:template match="a:actions" mode="a:input-show">
    <div class="input actions">
      <div class="key">
        <div>
          <xsl:call-template name="a:label-class-attr">
            <xsl:with-param name="error" select="concat(@error,a:selection/*/@error)"/>
          </xsl:call-template>
          <span>
            <xsl:value-of select="$o:params-l10n[@key='actions']"/>
          </span>
          <div class="spacer"/>
        </div>        
        <div class='hint'>
          <xsl:call-template name="a:input-hints">
            <xsl:with-param name="hint" select="$o:hints-l10n[@key='actions']"/>
          </xsl:call-template>
          <div class="spacer"/>
        </div>
        <div class="spacer"/>
      </div>  
      <div class="value">
        <xsl:apply-templates select="a:options" mode="o:actions-selection">
          <xsl:with-param name="selection" select="a:selection/*"/>
          <xsl:with-param name="name" select="'acl-actions'"/>
        </xsl:apply-templates>
        <div class="spacer"/>
      </div>    
      <div class="spacer"/>
    </div>
  </xsl:template>
  
  <xsl:template match="a:options" mode="o:actions-selection">
    <xsl:param name="selection"/>
    <xsl:param name="name"/>
    <xsl:choose>
      <xsl:when test="*">
        <xsl:apply-templates mode="o:actions-optgroup">
          <xsl:with-param name="selection" select="$selection"/>
          <xsl:with-param name="name" select="$name"/>
        </xsl:apply-templates>   
      </xsl:when>
      <xsl:otherwise>
        <span>
          <xsl:value-of select="$b:l10n/l:gentext[@key='none-available']"/>
        </span>
      </xsl:otherwise>
    </xsl:choose>    
  </xsl:template>
  
  <xsl:template match="a:optgroup" mode="o:actions-optgroup">
    <xsl:param name="selection"/>
    <xsl:param name="name"/>
    <div class="entry optgroup {@name}">  
      <div class="header">
        <div class="key">
          <span>
            <xsl:value-of select="$o:params-l10n[@key='app-key']"/>
          </span>
          <div class="spacer"/>
        </div>
        <div class="value">
          <span>
            <xsl:value-of select="@name"/>
          </span>
          <div class="spacer"/>
        </div>
        <div class="spacer"/>
      </div>  
      <div class="options">
        <xsl:apply-templates mode="o:actions-optgroup">
          <xsl:sort select="@key"/>
          <xsl:with-param name="selection" select="$selection"/>
          <xsl:with-param name="optgroup" select="@name"/>
          <xsl:with-param name="name" select="$name"/>
        </xsl:apply-templates>
        <div class="spacer"/>
      </div>      
      <div class="spacer"/> 
    </div>
  </xsl:template>
  
  <xsl:template match="a:option" mode="o:actions-optgroup">
    <xsl:param name="selection"/>
    <xsl:param name="optgroup"/>
    <xsl:param name="name"/>    
    <xsl:param name="key" select="@key"/>      
    <div class="option">
      <input type="checkbox" name="{$name}" value="{concat($optgroup,' ',$key)}">
        <xsl:if test="$selection[@optgroup=$optgroup and @key=$key]">
          <xsl:attribute name="checked">checked</xsl:attribute>
        </xsl:if>             
      </input>
      <span>
        <xsl:value-of select="@key"/>
      </span>
      <div class="spacer"/> 
    </div>
  </xsl:template>
  
  <xsl:template match="a:add-agent" mode="a:input-show">
    <div class='input add-agent'>  
      <div class="key">
        <div>
          <xsl:call-template name="a:label-class-attr">
            <xsl:with-param name="error" select="a:has-errors(*)"/>
          </xsl:call-template>
          <span><xsl:value-of select="$o:params-l10n[@key='add-agent']"/></span>
          <div class="spacer"/>
        </div>        
        <div class='hint'>
          <xsl:call-template name="a:input-hints">
            <xsl:with-param name="hint" select="$o:hints-l10n[@key='add-agent']"/>
          </xsl:call-template>
          <div class="spacer"/>
        </div>
        <div class="spacer"/>
      </div>      
      <div class='value'>
        <xsl:apply-templates mode="a:add-agent-input"/>        
        <div class="spacer"/>
      </div>
      <div class='spacer'/>
    </div>  
  </xsl:template>
  
  <xsl:template match="a:nick" mode="a:add-agent-input">
    <div class="entry nick-input">
      <div class="header add-agent-nick">
        <div>
          <xsl:call-template name="a:label-class-attr">
            <xsl:with-param name="class" select="'key'"/>
          </xsl:call-template>
          <span>
            <xsl:value-of select="$o:params-l10n[@key='add-agent-nick']"/>
          </span>
          <div class="spacer"/>
        </div>
        <div class="spacer"/>
      </div>
      <div class="options">
        <div class="option">
          <input class='medium' type="text" name="add-agent-nick"
            value="{.}"/>
          <div class="spacer"/>
        </div>
        <div class="spacer"/>
      </div>          
      <div class="spacer"/>
    </div>
  </xsl:template>
  
  <xsl:template match="a:permission" mode="a:add-agent-input">
    <div class="entry add-agent-permission">
      <div class="header">
        <div>
          <xsl:call-template name="a:label-class-attr">
            <xsl:with-param name="class" select="'key'"/>
          </xsl:call-template>
          <span>
            <xsl:value-of select="$o:params-l10n[@key='add-agent-permission']"/>
          </span>
          <div class="spacer"/>
        </div>            
        <div class="spacer"/>
      </div>
      <div class="options">
        <div class="option allow">
          <input type="radio" name="add-agent-permission" value="allow">
            <xsl:if test=".='allow'">
              <xsl:attribute name="checked">checked</xsl:attribute>
            </xsl:if>
          </input>
          <span>
            <xsl:value-of select="$o:params-l10n[@key='allow']"/>            
          </span>
          <div class="spacer"/>
        </div>
        <div class="option forbid">
          <input type="radio" name="add-agent-permission" value="forbid">
            <xsl:if test=".='forbid'">
              <xsl:attribute name="checked">checked</xsl:attribute>
            </xsl:if>
          </input>
          <span>
            <xsl:value-of select="$o:params-l10n[@key='forbid']"/>            
          </span>
          <div class="spacer"/>
        </div>
      </div>         
      <div class="spacer"/>
    </div>
  </xsl:template>
  
  <xsl:template match="a:permissions" mode="a:input-show">
    <div class="input permissions">
      <div class="key">
        <div>
          <xsl:call-template name="a:label-class-attr">
            <xsl:with-param name="error" select="a:has-errors(*)"/>
          </xsl:call-template>
          <span>
            <xsl:value-of select="$o:params-l10n[@key='permissions']"/>
          </span>
          <div class="spacer"/>
        </div>        
        <div class='hint'>
          <xsl:call-template name="a:input-hints">
            <xsl:with-param name="hint" select="$o:hints-l10n[@key='permissions']"/>
          </xsl:call-template>
          <div class="spacer"/>
        </div>
        <div class="spacer"/>
      </div>  
      <div class="value">
        <xsl:apply-templates mode="a:input-show"/>
        <div class="spacer"/>
      </div>    
      <div class="spacer"/>
    </div>   
  </xsl:template> 
  
  <xsl:template match="a:forbid" mode="a:input-show">
    <xsl:param name="key" select="local-name()"/>
    <div class="entry {$key}">
      <div class="header">
        <div>
          <xsl:call-template name="a:label-class-attr">
            <xsl:with-param name="class" select="'key'"/>
          </xsl:call-template>
          <span>
            <xsl:value-of select="$o:params-l10n[@key=$key]"/>
          </span>
          <div class="spacer"/>
        </div>        
        <div class="spacer"/>
      </div>  
      <div class="options agents">
        <xsl:choose>
          <xsl:when test="*">
            <xsl:apply-templates mode="a:input-show">
              <xsl:sort select="@nick"/>
              <xsl:with-param name="name" select="concat($key,'-agents')"/>
            </xsl:apply-templates>
          </xsl:when>
          <xsl:otherwise>
            <div class="option agent nobody">
              <span>
                <xsl:value-of select="$o:l10n/*[@key='nobody']"/>
              </span>
            </div>           
          </xsl:otherwise>
        </xsl:choose>        
        <div class="spacer"/>
      </div>    
      <div class="spacer"/>
    </div>
  </xsl:template>
  
  <xsl:template match="a:allow" mode="a:input-show">
    <xsl:param name="key" select="local-name()"/>
    <div class="entry {$key}">
      <div class="header">
        <div>
          <xsl:call-template name="a:label-class-attr">
            <xsl:with-param name="class" select="'key'"/>
          </xsl:call-template>
          <span>
            <xsl:value-of select="$o:params-l10n[@key=$key]"/>
          </span>
          <div class="spacer"/>
        </div>        
        <div class="spacer"/>
      </div>  
      <div class="options agents">
        <xsl:choose>
          <xsl:when test="*">            
            <xsl:apply-templates mode="a:input-show">
              <xsl:sort select="@nick"/>
              <xsl:with-param name="name" select="concat($key,'-agents')"/>
            </xsl:apply-templates>
          </xsl:when>
          <xsl:otherwise>
            <div class="option agent nobody">
              <span>
                <xsl:value-of select="$o:l10n/*[@key='nobody']"/>
              </span>
              <div class="spacer"/>
            </div>   
          </xsl:otherwise>
        </xsl:choose>        
        <div class="spacer"/>
      </div>    
      <div class="spacer"/>
    </div>
  </xsl:template>
  
  <xsl:template match="a:world" mode="a:input-show">
    <div class="entry allow-world">
      <div class="header">
        <div class="key">
          <xsl:call-template name="a:label-class-attr">
            <xsl:with-param name="class" select="'key'"/>
          </xsl:call-template>
          <span>
            <xsl:value-of select="$o:params-l10n[@key='world']"/>
          </span>
          <div class="spacer"/>
        </div>        
        <div class="spacer"/>
      </div>  
      <div class="options agents">
        <xsl:variable name="value" select="string(.)"/>
        <div class="option unset">
          <input name="world" value="" type="radio">
            <xsl:if test="$value=''">
              <xsl:attribute name="checked">checked</xsl:attribute>
            </xsl:if>
          </input>     
          <span>
            <xsl:value-of select="$o:hints-l10n[@key='unset']"/>
          </span>
          <div class="spacer"/>
        </div>
        <div class="option allow">
          <input name="world" value="1" type="radio">
            <xsl:if test="$value='1'">
              <xsl:attribute name="checked">checked</xsl:attribute>
            </xsl:if>
          </input>     
          <span>
            <xsl:value-of select="$o:hints-l10n[@key='allow']"/>
          </span>
          <div class="spacer"/>
        </div>
        <div class="option forbid">
          <input name="world" value="0" type="radio">
            <xsl:if test="$value='0'">
              <xsl:attribute name="checked">checked</xsl:attribute>
            </xsl:if>
          </input>     
          <span>
            <xsl:value-of select="$o:hints-l10n[@key='forbid']"/>
          </span>
          <div class="spacer"/>
        </div>
        <div class="spacer"/>
      </div>      
      <div class="spacer"/>
    </div>
  </xsl:template>  
  
  <xsl:template match="a:agent" mode="a:input-show">
    <xsl:param name='name'/>
    <div class="option agent">
      <input name="{$name}" value="{@nick}" type="checkbox" checked="checked"/>
      <xsl:choose>
        <xsl:when test="@profile-id">
          <a href="{a:format-url(a:public-url(@profile-id))}" title="{@name}">
            <xsl:value-of select="@nick"/>
          </a>
        </xsl:when>
        <xsl:otherwise>
          <span>
            <xsl:value-of select="@nick"/>
          </span>
        </xsl:otherwise>
      </xsl:choose>      
      <div class="spacer"/>
    </div>
  </xsl:template>  
 
</xsl:stylesheet>

